﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapWTEINZ(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWTEINZ(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            try
            { 
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWTEINZ(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapWTEINZ(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWTEINZ(dwLocal);
            }
            UpdateWTEINZ(dwLocal);
        }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
}
        public void InsertWTEINZ(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO WTEINZ(WTEMANDANT, WTEEINZNR, WTESTAKZ, WTEBEZ, WTEEZ, WTEERSFD, WTERAPP, WTEEZWBL, WTEESTBRT, WTEWBLBRT, WTEWBLTL, WTELSL01, WTEGEW01, WTELSR01, WTELEER01, WTELSL02, WTEGEW02, WTELSR02, WTELEER02, WTELSL03, WTEGEW03, WTELSR03, WTELEER03, WTELSL04, WTEGEW04, WTELSR04, WTELEER04, WTELSL05, WTEGEW05, WTELSR05, WTELEER05, WTEAENDZL, WTEAENDBEN, WTEAENDDAT, WTENEUBEN, WTENEUDAT, WTEFILLER)"
                + " VALUES ("
            + " :WTEMANDANT,:WTEEINZNR, 'A', '                              ', 'G', 0, 1, '2                                       ', '                                        ', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, '        ', 0, :WTENEUBEN, :WTENEUDAT, '                                          ')";
            or1.Parameters.Add("WTEMANDANT", OracleType.NVarChar).Value = dwData["WTEMANDANT"].ToString();
            or1.Parameters.Add("WTEEINZNR", OracleType.NVarChar).Value = dwData["WTEEINZNR"].ToString();
            or1.Parameters.Add("WTENEUBEN", OracleType.NVarChar).Value = dwData["WTENEUBEN"].ToString();
            or1.Parameters.Add("WTENEUDAT", OracleType.NVarChar).Value = dwData["WTENEUDAT"].ToString();
            Connect2Proxy(or1);
        }
        public void DeleteWTEINZ(string client, string art)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE WTEINZ WHERE WTEMANDANT=:WTEMANDANT AND WTEEINZNR=:WTEEINZNR";
            or1.Parameters.Add("WTEMANDANT", OracleType.NVarChar).Value = client;
            or1.Parameters.Add("WTEEINZNR", OracleType.NVarChar).Value = art;
            Connect2Proxy(or1);
        }
        public DataSet QueryWTEINZ(DataRow dwData)
        {
            DataSet set4Return = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT *FROM  WTEINZ "
                + "  WHERE WTEMANDANT=:WTEMANDANT AND WTEEINZNR=:WTEEINZNR";
            or1.Parameters.Add("WTEMANDANT", OracleType.NVarChar).Value = dwData["WTEMANDANT"].ToString();
            or1.Parameters.Add("WTEEINZNR", OracleType.NVarChar).Value = dwData["WTEEINZNR"].ToString();
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "WTEINZ";
            }
            set4Return.Merge(Result);
            return set4Return;
        }
        public void UpdateWTEINZ(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE WTEINZ SET "
                 + "WTEMANDANT=:WTEMANDANT,"
                 + "WTEEINZNR=:WTEEINZNR,"
                 + "WTESTAKZ=:WTESTAKZ,"
                 + "WTEBEZ=:WTEBEZ,"
                 + "WTEEZ=:WTEEZ,"
                 + "WTEERSFD=:WTEERSFD,"
                 + "WTERAPP=:WTERAPP,"
                 + "WTEEZWBL=:WTEEZWBL,"
                 + "WTEESTBRT=:WTEESTBRT,"
                 + "WTEWBLBRT=:WTEWBLBRT,"
                 + "WTEWBLTL=:WTEWBLTL,"
                 + "WTELSL01=:WTELSL01,"
                 + "WTEGEW01=:WTEGEW01,"
                 + "WTELSR01=:WTELSR01,"
                 + "WTELEER01=:WTELEER01,"
                 + "WTELSL02=:WTELSL02,"
                 + "WTEGEW02=:WTEGEW02,"
                 + "WTELSR02=:WTELSR02,"
                 + "WTELEER02=:WTELEER02,"
                 + "WTELSL03=:WTELSL03,"
                 + "WTEGEW03=:WTEGEW03,"
                 + "WTELSR03=:WTELSR03,"
                 + "WTELEER03=:WTELEER03,"
                 + "WTELSL04=:WTELSL04,"
                 + "WTEGEW04=:WTEGEW04,"
                 + "WTELSR04=:WTELSR04,"
                 + "WTELEER04=:WTELEER04,"
                 + "WTELSL05=:WTELSL05,"
                 + "WTEGEW05=:WTEGEW05,"
                 + "WTELSR05=:WTELSR05,"
                 + "WTELEER05=:WTELEER05,"
                 + "WTEAENDZL=:WTEAENDZL,"
                 + "WTEAENDBEN=:WTEAENDBEN,"
                 + "WTEAENDDAT=:WTEAENDDAT,"
                 + "WTENEUBEN=:WTENEUBEN,"
                 + "WTENEUDAT=:WTENEUDAT,"
                 + "WTEFILLER=:WTEFILLER "
            + " WHERE  "
            + "  WTEMANDANT=:WTEMANDANT AND WTEEINZNR=:WTEEINZNR";
            or1.Parameters.Add("WTEMANDANT", OracleType.NVarChar).Value = dwData["WTEMANDANT"].ToString();
            or1.Parameters.Add("WTEEINZNR", OracleType.NVarChar).Value = dwData["WTEEINZNR"].ToString();
            or1.Parameters.Add("WTESTAKZ", OracleType.NVarChar).Value = dwData["WTESTAKZ"].ToString();
            or1.Parameters.Add("WTEBEZ", OracleType.NVarChar).Value = dwData["WTEBEZ"].ToString();
            or1.Parameters.Add("WTEEZ", OracleType.NVarChar).Value = dwData["WTEEZ"].ToString();
            or1.Parameters.Add("WTEERSFD", OracleType.NVarChar).Value = dwData["WTEERSFD"].ToString();
            or1.Parameters.Add("WTERAPP", OracleType.NVarChar).Value = dwData["WTERAPP"].ToString();
            or1.Parameters.Add("WTEEZWBL", OracleType.NVarChar).Value = dwData["WTEEZWBL"].ToString();
            or1.Parameters.Add("WTEESTBRT", OracleType.NVarChar).Value = dwData["WTEESTBRT"].ToString();
            or1.Parameters.Add("WTEWBLBRT", OracleType.NVarChar).Value = dwData["WTEWBLBRT"].ToString();
            or1.Parameters.Add("WTEWBLTL", OracleType.NVarChar).Value = dwData["WTEWBLTL"].ToString();
            or1.Parameters.Add("WTELSL01", OracleType.NVarChar).Value = dwData["WTELSL01"].ToString();
            or1.Parameters.Add("WTEGEW01", OracleType.NVarChar).Value = dwData["WTEGEW01"].ToString();
            or1.Parameters.Add("WTELSR01", OracleType.NVarChar).Value = dwData["WTELSR01"].ToString();
            or1.Parameters.Add("WTELEER01", OracleType.NVarChar).Value = dwData["WTELEER01"].ToString();
            or1.Parameters.Add("WTELSL02", OracleType.NVarChar).Value = dwData["WTELSL02"].ToString();
            or1.Parameters.Add("WTEGEW02", OracleType.NVarChar).Value = dwData["WTEGEW02"].ToString();
            or1.Parameters.Add("WTELSR02", OracleType.NVarChar).Value = dwData["WTELSR02"].ToString();
            or1.Parameters.Add("WTELEER02", OracleType.NVarChar).Value = dwData["WTELEER02"].ToString();
            or1.Parameters.Add("WTELSL03", OracleType.NVarChar).Value = dwData["WTELSL03"].ToString();
            or1.Parameters.Add("WTEGEW03", OracleType.NVarChar).Value = dwData["WTEGEW03"].ToString();
            or1.Parameters.Add("WTELSR03", OracleType.NVarChar).Value = dwData["WTELSR03"].ToString();
            or1.Parameters.Add("WTELEER03", OracleType.NVarChar).Value = dwData["WTELEER03"].ToString();
            or1.Parameters.Add("WTELSL04", OracleType.NVarChar).Value = dwData["WTELSL04"].ToString();
            or1.Parameters.Add("WTEGEW04", OracleType.NVarChar).Value = dwData["WTEGEW04"].ToString();
            or1.Parameters.Add("WTELSR04", OracleType.NVarChar).Value = dwData["WTELSR04"].ToString();
            or1.Parameters.Add("WTELEER04", OracleType.NVarChar).Value = dwData["WTELEER04"].ToString();
            or1.Parameters.Add("WTELSL05", OracleType.NVarChar).Value = dwData["WTELSL05"].ToString();
            or1.Parameters.Add("WTEGEW05", OracleType.NVarChar).Value = dwData["WTEGEW05"].ToString();
            or1.Parameters.Add("WTELSR05", OracleType.NVarChar).Value = dwData["WTELSR05"].ToString();
            or1.Parameters.Add("WTELEER05", OracleType.NVarChar).Value = dwData["WTELEER05"].ToString();
            or1.Parameters.Add("WTEAENDZL", OracleType.NVarChar).Value = dwData["WTEAENDZL"].ToString();
            or1.Parameters.Add("WTEAENDBEN", OracleType.NVarChar).Value = dwData["WTEAENDBEN"].ToString();
            or1.Parameters.Add("WTEAENDDAT", OracleType.NVarChar).Value = dwData["WTEAENDDAT"].ToString();
            or1.Parameters.Add("WTENEUBEN", OracleType.NVarChar).Value = dwData["WTENEUBEN"].ToString();
            or1.Parameters.Add("WTENEUDAT", OracleType.NVarChar).Value = dwData["WTENEUDAT"].ToString();
            or1.Parameters.Add("WTEFILLER", OracleType.NVarChar).Value = dwData["WTEFILLER"].ToString();
            Connect2Proxy(or1);
        }
    }
}
